package com.yikaiye.android.yikaiye.ui.fragment;

import android.os.Bundle;

import com.yikaiye.android.yikaiye.R;
import com.yikaiye.android.yikaiye.base.BaseFragment;
import com.yikaiye.android.yikaiye.config.Constant;
import com.yikaiye.android.yikaiye.databinding.FragmentCompanyServiceProgressBinding;
import com.yikaiye.android.yikaiye.ui.activity.mine.viewmodel.CompanyDetailsViewModel;
import com.yikaiye.android.yikaiye.ui.adapter.ServiceAdapter;

/**
 * 企业服务进度
 */
public class CompanyServiceProgressFragment extends BaseFragment<FragmentCompanyServiceProgressBinding, CompanyDetailsViewModel> {

    private ServiceAdapter adapter;

    public static CompanyServiceProgressFragment newInstance(String creditNo) {
        Bundle bundle = new Bundle();
        bundle.putString(Constant.CREDIT_NO_KEY, creditNo);
        CompanyServiceProgressFragment fragment = new CompanyServiceProgressFragment();
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    protected CompanyDetailsViewModel bindModel() {
        return getViewModel(this, CompanyDetailsViewModel.class);
    }

    @Override
    protected void initInject() {
        getFragmentComponent().inject(this);
    }

    @Override
    protected void initData() {

    }

    @Override
    public void lazyLoadData() {
        adapter = new ServiceAdapter(1, mContext);
        binding.recyclerView.setAdapter(adapter);
        adapter.setEmptyViewEnable(true);
        adapter.setEmptyViewLayout(mContext, R.layout.layout_empty_list);
        if (getArguments() != null) {
            String creditNo = getArguments().getString(Constant.CREDIT_NO_KEY);
            viewModel.getServiceByCreditNo(creditNo);
        }
    }

    @Override
    protected void initClick() {
        viewModel.serviceProgressListModelMutableLiveData.observe(this, serviceModels -> {
            adapter.submitList(serviceModels);
        });
    }
}
